﻿package birdry.control	{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	
	/**
	* ...
	* @author 
	*/
	public class ControllMove extends Sprite	{
		
		var _object:DisplayObject;
		var _accel:Number = 0;
		var _speed:Number;
		var _accelValue:Number;
		var _noneAccel:Number;
		
		public static const LEFT:String = "left";
		public static const RIGHT:String = "right";
		public static const TOP:String = "top";
		public static const BOTTOM:String = "bottom";
		
		//	accelValue 가 0일때는 감속효과를 없앨수 있다.
		public function ControllMove(object:DisplayObject, accelValue:Number=0.25, speed:Number=3): void	{
			_object = object;
			_accelValue = accelValue;
			_speed = speed;
		}
		
		public function move( direct: String ): void	{
			switch ( direct )	{
				case ControllMove.LEFT :
					_accel = _accel - _speed;
				break;
				case ControllMove.RIGHT :
					_accel = _accel + _speed;
				break;
				case ControllMove.TOP :
				break;
				case ControllMove.BOTTOM :
				break;
			}
		}
		
		public function play(): void	{
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
		
		public function stop(): void	{
			removeEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
		
		private function onEnterFrame( e: Event ): void	{
			if ( _accelValue != 0)		{
				_accel += _accelValue * (0 - _accel);
				_object.x += _accel;
			}	else 	{
				_object.x += _accel;
				_accel = 0;
			}
		}
		
	}	// class
	
}	// package